<template>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" :class="method==='view'?'readonly':''"  :disabled="method==='view'" @keyup.enter.native="doSubmit()"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="序号" prop="number"
                :rules="[
                 ]">
              <el-input v-model="inputForm.number" placeholder="请填写序号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="编码" prop="coding"
                :rules="[
                 ]">
              <el-input v-model="inputForm.coding" placeholder="请填写编码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="装置(部件) 名称" prop="name.id"
                :rules="[
                 ]">
              <el-input v-model="inputForm.name.id" placeholder="请填写装置(部件) 名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="给油脂部位" prop="part"
                :rules="[
                 ]">
              <el-input v-model="inputForm.part" placeholder="请填写给油脂部位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="润滑方式" prop="method"
                :rules="[
                 ]">
              <el-input v-model="inputForm.method" placeholder="请填写润滑方式"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="油脂牌号" prop="card"
                :rules="[
                 ]">
              <el-input v-model="inputForm.card" placeholder="请填写油脂牌号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="润滑点数" prop="a"
                :rules="[
                 ]">
              <el-input v-model="inputForm.a" placeholder="请填写润滑点数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="油量L" prop="b"
                :rules="[
                 ]">
              <el-input v-model="inputForm.b" placeholder="请填写油量L"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="周期" prop="c"
                :rules="[
                 ]">
              <el-input v-model="inputForm.c" placeholder="请填写周期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="油量L" prop="d"
                :rules="[
                 ]">
              <el-input v-model="inputForm.d" placeholder="请填写油量L"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="周期" prop="e"
                :rules="[
                 ]">
              <el-input v-model="inputForm.e" placeholder="请填写周期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="点检" prop="check"
                :rules="[
                 ]">
              <el-input v-model="inputForm.check" placeholder="请填写点检"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="检修" prop="repair"
                :rules="[
                 ]">
              <el-input v-model="inputForm.repair" placeholder="请填写检修"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="岗位" prop="post"
                :rules="[
                 ]">
              <el-input v-model="inputForm.post" placeholder="请填写岗位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="责任人" prop="people"
                :rules="[
                 ]">
              <el-input v-model="inputForm.people" placeholder="请填写责任人"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button v-if="method === 'add'" type="primary" @click="continueDoSubmit()">继续添加</el-button>
      <el-button @click="visible = false">关闭</el-button>
      <el-button v-if="method !== 'view'" type="primary" @click="doSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        oldInputForm: '',
        inputForm: {
          id: '',
          number: '',
          coding: '',
          name: {
            id: ''
          },
          part: '',
          method: '',
          card: '',
          a: '',
          b: '',
          c: '',
          d: '',
          e: '',
          check: '',
          repair: '',
          post: '',
          people: ''
        }
      }
    },
    components: {
    },
    methods: {
      init (method, obj) {
        this.method = method
        if (method === 'add') {
          this.title = `新建设备给油脂标准`
        } else if (method === 'edit') {
          this.title = '修改设备给油脂标准'
        } else if (method === 'view') {
          this.title = '查看设备给油脂标准'
        }
        this.visible = true
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          this.inputForm.id = ''
          this.oldInputForm = ''
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.oldInputForm = obj
            this.inputForm = JSON.parse(JSON.stringify(obj))
          }
        })
      },
   // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.$emit('addRow', this.oldInputForm, JSON.parse(JSON.stringify(this.inputForm)))
            this.visible = false
          }
        })
      },
      continueDoSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.$emit('addRow', this.oldInputForm, JSON.parse(JSON.stringify(this.inputForm)))
            this.$refs['inputForm'].resetFields()
          }
        })
      }
    }
  }
</script>